package com.audaque.core;

import java.io.IOException;
import java.io.InputStream;
import java.util.Properties;

import org.apache.commons.logging.LogFactory;

/**
 * 整个应用通用的常量 <br>
 * <b>类描述:</b>
 *
 * @see
 * @since
 */
public class CommonConstant {

	public static Integer JOB_NUMBER = null;
	public static Integer THREAD_NUMBER = null;
	public static Integer BUFFER_NUMBER = null;
	public static String MYSQL_ENGINE = null;

	public static final String MYSQL_ENGINE_MYISAM = "myisam";
	public static final String MYSQL_ENGINE_INNODB = "innodb";

	static {
		doLoadConfig();
	}

	private static void doLoadConfig() {
		InputStream is = CommonConstant.class.getResourceAsStream("/config.properties");
		try {
			Properties props = new Properties();
			props.load(is);
			JOB_NUMBER = Integer.parseInt(props.getProperty("job_number"));
			THREAD_NUMBER = Integer.parseInt(props.getProperty("thread_number"));
			BUFFER_NUMBER = Integer.parseInt(props.getProperty("buffer_number"));
			MYSQL_ENGINE = props.getProperty("mysql_engine");
		} catch (IOException e) {
			LogFactory.getLog(CommonConstant.class).error("读取配置文件出错！", e);
		} finally {
			try {
				is.close();
			} catch (IOException e) {
			}
		}
	}
}
